#!/bin/sh

set -e

case "${1}" in
    configure)
        if ! getent passwd | grep -q "^openerp:"; then
            adduser --system --no-create-home --quiet --gecos 'OpenERP' --group openerp
        fi
        # Register "openerp" as a postgres superuser 
        su - postgres -c "createuser -s openerp" 2> /dev/null || true
        chown openerp:openerp /etc/openerp/openerp-server.conf
        chmod 0640 /etc/openerp/openerp-server.conf
        # Creating log file
        mkdir -p /var/log/openerp/
        chown openerp:openerp /var/log/openerp
        chmod 0750 /var/log/openerp
        # Creating local storage directory
        mkdir -p /var/lib/openerp/filestore
        chown openerp:openerp -R /var/lib/openerp
        # update-python-modules NOW otherwise invoke-rc.d openerp start will fail
        update-python-modules -p openerp.public
        ;;
    *)
        ;;
esac

#DEBHELPER#

exit 0
